<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="th/include/common_head :: head(~{::title}, ~{::link}, ~{::style})">
    <title>安全配置</title>
    <link type="text/css" rel="stylesheet" th:href="@{${skinPath} + '/css.css'}"/>
    <style>
        .table th, .table td {
            vertical-align: middle !important;
        }
    </style>
</head>
<div th:replace="th/include/tab_config :: navConfig(5)"></div>
<div class="spacerH"></div>
<div class="container" style="margin-top: 10px">
    <div class="row">
        <div class="col-lg-10 col-lg-offset-1">
            <div class="table-responsive">
                <table class="table table-bordered table-hover">
                    <thead>
                    <tr>
                        <td colspan="3" class="tabStyle_1_title">安全配置信息</td>
                    </tr>
                    </thead>
                    <tbody th:each="json, stat : ${jsonAry}">
                    <form method="post" th:id="'form' + ${stat.index}" onsubmit="return false">
                        <tr>
                            <td width='52%'>
                                <input type="hidden" name="name" th:value="${json[name]}"/>
                                &nbsp;[[${json[desc]}]]
                            </td>
                            <td width='34%' class="form-inline form-group">
                                <th:block th:if="${json[value]} eq 'true' or ${json[value]} eq 'false'">
                                    <select th:id="'attr' + ${stat.index}" name="value" class="form-control">
                                        <option value="true">是</option>
                                        <option value="false">否</option>
                                    </select>
                                    <script th:inline="javascript">
                                        $('#attr' + [[${stat.index}]]).val([[${json[value]}]]);
                                    </script>
                                </th:block>

                                <th:block th:switch="${json[optAry]} == null">
                                    <th:block th:case="true" th:if="!(${json[value]} eq 'true' or ${json[value]} eq 'false')">
                                        <input type="text" th:value="${json[value]}" name="value" size="30" class="form-control"/>
                                    </th:block>
                                    <select th:case="*" th:id="'attr' + ${stat.index}" name="value" class="form-control">
                                        <th:block th:each="opt, statOpt : ${json[optAry]}">
                                            <option th:value="${opt[value]}">[[${opt[name]}]]</option>
                                        </th:block>
                                    </select>
                                    <script th:inline="javascript">
                                        $(function () {
                                            $('#attr[(${stat.index})]').val([[${json[value]}]]);
                                        })
                                    </script>
                                </th:block>
                            </td>
                            <td width="14%" align="center">
                                <button class="btn btn-default" th:onclick="submitForm('form' + [[${stat.index}]])">修改</button>
                            </td>
                        </tr>
                    </form>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
</body>
<script th:inline="javascript">
    function submitForm(formId) {
        $.ajax({
            type: "post",
            url: "editSecurityConfig.do",
            data: $('#' + formId).serialize(),
            dataType: "json",
            beforeSend: function(XMLHttpRequest) {
                $('body').showLoading();
            },
            success: function(data, status){
                jAlert(data.msg, "提示");
            },
            complete: function(XMLHttpRequest, status){
                $('body').hideLoading();
            },
            error: function(){
                //请求出错处理
                alert(XMLHttpRequest.responseText);
            }
        });

        window.event? window.event.cancelBubble = true : e.stopPropagation();
    }
</script>
</html>